﻿<%@ WebHandler Language="C#" Class="AutoComplete" %>

using System;
using System.Web;
using System.Collections.Generic;
using TierApplication;
using System.Data;

public class AutoComplete : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        string prefixText = context.Request.QueryString["q"].ToString();
        string sRetrun = string.Empty;
        if (string.IsNullOrEmpty(prefixText) == false)
        {
            TierApplication.T_PRODUCT product = new T_PRODUCT();
            DataSet ds = product.GetList(" productname like '%" + prefixText + "%'");
            if (ds != null && ds.Tables.Count != 0 && ds.Tables[0].Rows.Count != 0)
            {
                for (int i = 0; i <  ds.Tables[0].Rows.Count; i++)
                {
                    sRetrun += ds.Tables[0].Rows[i]["productname"].ToString()+Environment.NewLine;
                }
            }
        }
        context.Response.Write(sRetrun);
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}